package org.lds.hotkey.console.business.rule.model.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Range;
import org.lds.hotkey.common.model.pojo.request.BaseCreateRequest;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 新建 - 请求
 *
 * @author lidongsheng
 * @since 2024-06-05
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Accessors(chain = true)
public class RuleBaseCreateRequest extends BaseCreateRequest implements Serializable {
    private static final long serialVersionUID = 1L;


    /**
     * app主键
     */
    @NotNull(message = "appId不能为空")
    private Long appId;


    /**
     * key规则
     */
    @NotBlank(message = "key不能为空")
    private String key;

    public void setKey(String key) {
        this.key = StringUtils.trimToNull(key);
    }

    /**
     * 是否是前缀。 1：是 0：否
     */
    @NotNull(message = "prefix不能为空")
    private Boolean prefix;


    /**
     * 间隔时间（秒）
     */
    @NotNull(message = "interval不能为空")
    @Range(min = 1, max = 100000)
    private Integer interval;


    /**
     * 累计数量
     */
    @NotNull(message = "threshold不能为空")
    @Range(min = 1, max = 100000)
    private Integer threshold;


    /**
     * 缓存时间（秒）
     */
    @NotNull(message = "duration不能为空")
    @Range(min = 1, max = 5000)
    private Integer duration;


    /**
     * 描述
     */
    private String desc;

    /**
     * 优先级 值越小优先级越高
     */
    @NotNull(message = "priority不能为空")
    @Range(min = 0, max = 999999)
    private Integer priority;

    public void setDesc(String desc) {
        this.desc = StringUtils.trimToNull(desc);
    }


}
